package org.onejava.core.tools;

import java.util.HashMap;
import java.util.Map;

import org.onejava.core.bean.Allconfig;
import org.onejava.core.bean.MContext;

public class ActionTools {
	public static String getClassPath(String ServletPath){
		//获取:\..class路径\Action！method
		String path = ServletPath.split("\\.")[0];
		String[] urlPath = path.split("/");
		//获取：Action！method
		String className = urlPath[urlPath.length-1];
		StringBuffer s = new StringBuffer();
		if(!"".equals(Allconfig.ACTION_ROOT)){
			String root = Allconfig.ACTION_ROOT;
			root = root.replace("/", ".");
			s.append(root+".");
		}
		
		for(int i=1;i<urlPath.length-1;i++){
			
			s.append(urlPath[i]);
			s.append(".");
		}
		String classAddress = s.toString();	
		
		String classPath = classAddress+className;
		
		return classPath;
		
	} 
	public static Map<String,String> getMethodAndClassPath(String ServletPath){
		//获取:\..class路径\Action！method
		String path = ServletPath.split("\\.")[0];
		String[] urlPath = path.split("/");
		//获取：Action！method
		String className = urlPath[urlPath.length-1];
		StringBuffer s = new StringBuffer();
		if(!"".equals(Allconfig.ACTION_ROOT)){
			String root = Allconfig.ACTION_ROOT;
			root = root.replace("/", ".");
			s.append(root+".");
		}
		
		for(int i=1;i<urlPath.length-1;i++){
			s.append(urlPath[i]);
			s.append(".");
		}
		String classAddress = s.toString();	
		//分割class和方法
		String[] methodPath = className.split("!");
		String methodName = Allconfig.defaultMethod; 
		if(methodPath.length>1){
			className=methodPath[0];
			methodName=methodPath[methodPath.length-1];
		}
		String classPath = classAddress+className;
		Map map =  new HashMap(3);
		map.put("methodName", methodName);
		map.put("classPath", classPath);
		map.put("className", className);
		return map;
		
	}
}
